package com.nchu.controller;

import com.nchu.common.util.PageResult;
import com.nchu.common.util.R;
import com.nchu.entity.Orders;
import com.nchu.entity.User;
import com.nchu.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yaojie
 * @since 2025-01-09
 */
@RestController
@CrossOrigin //配置跨域
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @GetMapping("/list")
    public R list(){
        List<Orders> orderList = orderService.list();
        return R.ok().data("orderList",orderList);
    }
    @GetMapping("/findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable("page") Integer page,
                        @PathVariable("pageSize") Integer pageSize) {
        PageResult<Orders> pr = orderService.findByPage(page,pageSize);
        //返回结果
        return R.ok().data("pr",pr);
    }
    //删除订单信息这里的id可以填多个id如/1,3,4
    @PostMapping("/deleteOrder/{id}")
    public R delete(@PathVariable("id") String id){
        String[] split = id.split(",");
        List<String> orderIds = Arrays.asList(split);
        return orderService.removeByIds(orderIds) ? R.ok().message("删除菜品信息成功!") : R.error().message("删除菜品信息失败!");
    }
}
